package no.ntnu.fp.watch.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;
import javax.swing.JButton;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import no.ntnu.fp.model.Platform;
import no.ntnu.fp.model.Well;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewWellDialog extends JDialog {
	private JLabel tempLimitLabel;
	private JLabel pressureLimitLabel;
	private JLabel deltaTLimitLabel;
	private JTextField dTLimitField;
	private JTextField resistanceLimitField;
	private JTextField pressureLimitField;
	private JTextField tempLimitField;
	private JTextField evLimitField;
	private JLabel dPlimitLabel;
	private JLabel resistanceLimitLabel;
	private JButton cancelButton;
	private JButton saveButton;
	private JTextField dPLimitField;
	private JLabel evLabel;
	
	private Platform platform;
	
	public NewWellDialog(Platform p){
		this.platform = p;
		this.initGUI();
		this.setTitle("Create new well");
		this.setAlwaysOnTop(true);
		this.setVisible(true);
		this.setSize(400, 400);
		this.setLocationRelativeTo(null);
		
	}

	private void initGUI() {
		try {
			AnchorLayout thisLayout = new AnchorLayout();
			getContentPane().setLayout(thisLayout);
			{
				cancelButton = new JButton();
				getContentPane().add(cancelButton, new AnchorConstraint(822, 811, 903, 536, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				cancelButton.setText("Cancel");
				cancelButton.setPreferredSize(new java.awt.Dimension(103, 28));
				cancelButton.addActionListener(new cancelActionListener(this));
			}
			{
				saveButton = new JButton();
				getContentPane().add(saveButton, new AnchorConstraint(822, 455, 903, 180, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				saveButton.setText("Save");
				saveButton.setPreferredSize(new java.awt.Dimension(103, 28));
				saveButton.addActionListener(new saveActionListener(this));
			}
			{
				dPLimitField = new JTextField("0");
				getContentPane().add(dPLimitField, new AnchorConstraint(641, 937, 704, 632, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				dPLimitField.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				dTLimitField = new JTextField("0");
				getContentPane().add(dTLimitField, new AnchorConstraint(497, 937, 560, 632, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				dTLimitField.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				resistanceLimitField = new JTextField("0");
				getContentPane().add(resistanceLimitField, new AnchorConstraint(384, 937, 448, 632, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				resistanceLimitField.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				pressureLimitField = new JTextField("0");
				getContentPane().add(pressureLimitField, new AnchorConstraint(266, 937, 329, 632, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				pressureLimitField.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				tempLimitField = new JTextField("0");
				getContentPane().add(tempLimitField, new AnchorConstraint(151, 937, 214, 632, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				tempLimitField.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				evLimitField = new JTextField("0");
				getContentPane().add(evLimitField, new AnchorConstraint(44, 937, 108, 632, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				evLimitField.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				dPlimitLabel = new JLabel();
				getContentPane().add(dPlimitLabel, new AnchorConstraint(638, 407, 701, 102, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				dPlimitLabel.setText("dP limit");
				dPlimitLabel.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				deltaTLimitLabel = new JLabel();
				getContentPane().add(deltaTLimitLabel, new AnchorConstraint(494, 407, 557, 102, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				deltaTLimitLabel.setText("dT limit");
				deltaTLimitLabel.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				resistanceLimitLabel = new JLabel();
				getContentPane().add(resistanceLimitLabel, new AnchorConstraint(381, 407, 445, 102, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				resistanceLimitLabel.setText("Resistance Limit");
				resistanceLimitLabel.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				pressureLimitLabel = new JLabel();
				getContentPane().add(pressureLimitLabel, new AnchorConstraint(263, 407, 327, 102, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				pressureLimitLabel.setText("Pressure Limit");
				pressureLimitLabel.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				tempLimitLabel = new JLabel();
				getContentPane().add(tempLimitLabel, new AnchorConstraint(151, 407, 214, 102, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				tempLimitLabel.setText("Temperature Limit");
				tempLimitLabel.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			{
				evLabel = new JLabel();
				getContentPane().add(evLabel, new AnchorConstraint(50, 407, 113, 102, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				evLabel.setText("EV limit");
				evLabel.setPreferredSize(new java.awt.Dimension(114, 22));
			}
			pack();
		} catch(Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
	class saveActionListener implements ActionListener{
		private NewWellDialog newWellDialog;
		
		public saveActionListener(NewWellDialog nwd){
			this.newWellDialog = nwd;
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			newWellDialog.dispose();
			int critT = Integer.parseInt(tempLimitField.getText());
			int critR = Integer.parseInt(resistanceLimitField.getText());
			int critP = Integer.parseInt(pressureLimitField.getText());
			int evLimit = Integer.parseInt(evLimitField.getText());
			int dtLimit = Integer.parseInt(dTLimitField.getText());
			int dpLimit = Integer.parseInt(dPLimitField.getText());
			
			
			platform.addWell(new Well(critT, critR, critP, evLimit, dtLimit, dpLimit, dpLimit, dpLimit, platform,false), false);
			
		}
		
	}
	
	class cancelActionListener implements ActionListener{
		private NewWellDialog newWellDialog;
		
		public cancelActionListener(NewWellDialog nwd){
			this.newWellDialog = nwd;
		}
		
		@Override
		public void actionPerformed(ActionEvent e) {
			newWellDialog.dispose();
			
		}
		
	}
	

}
